<script type="text/javascript">
	
	$(document).ready(function() {
	    
		// CRUD
		add_data = function (){
			$('#dialog').dialog({
				title: 'Tambah Data Akun',
				width: 500,
				height: 310,
				closed: true,
				cache: false,
				href: base_url+'akun/add',
				modal: true
			});
			 
			$('#dialog').dialog('open');
			url = base_url+'akun/save/add';
		}

		edit_data = function (id){
			$('#dialog').dialog({
				title: 'Edit Data Akun',
				width: 500,
				height: 310,
				closed: true,
				cache: false,
				href: base_url+'akun/edit/'+id,
				modal: true
			});
			 
			$('#dialog').dialog('open');
			url = base_url+'akun/save/edit';
		}

		saveData = function(){
			$('#form1').form('submit',{
				url: url,
				onSubmit: function(){
					return $(this).form('validate');
				},
				success: function(result){
					//alert(result);
					var result = eval('('+result+')');
					if (result.success){
						$('#dialog').dialog('close');		// close the dialog
						$('#tt').treegrid('reload');
					} else {
						$.messager.show({
							title: 'Error',
							msg: result.msg
						});
					}
				}
			});
			
		}

		// formatter
		aksi = function(value, row, index){
			return '<a href="#" onclick="javascript:edit_data(\''+row.kode_akun+'\');" alt="Edit Data" class="easyui-linkbutton" iconCls="icon-edit">Edit</a>';
		}

	    $('#tt').treegrid({
		    url:'<?=base_url()?>akun/grid',
		    idField:'kode_akun',
		    treeField:'deskripsi',
		    columns:[[
			    {	title:'Kode Akun',
			    	field:'kode_akun',
			    	width:100
			   	},
			    {
			    	title:'Deskripsi',
			    	field:'deskripsi',
			    	width:400,
			    	align:'left'
			    },
			    {
			    	title:'Aksi',
			    	field:'act',
			    	width:100,
			    	align:'left',
			    	formatter: aksi,
			    },
		    ]],
		    fit:true
	    });


	});

</script>
<div id="toolbar" style="padding:5px;height:auto">
	<table width="50%" border="0">
	<tr>
		<td><a href="#" class="easyui-linkbutton btn" iconCls="icon-search" onclick="add_data()">Tambah Akun</a></td>
	</tr>
	</table>
</div>
<table id="tt" style="width:600px;height:400px"></table>